﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace StockUtil
{
    public class SingletonRegistry
    {
        private static SingletonRegistry _instance = new SingletonRegistry();

        private static Dictionary<Type, Object> map = new Dictionary<Type, Object>();

        private SingletonRegistry()
        {
        }

        public static Object getInstance(Type type)
        {
            if (map.ContainsKey(type))
            {
                return map[type];
            }

            try
            {
                return Activator.CreateInstance(type);
            }
            catch (Exception ex)
            {
                throw new Exception("类型实例化失败！");
            }

            return null;
        }
    }
}
